# @Author: Eric Ito
# @Date: 1/29/2009
# @Name: Project Euler Problem 32

"""
pandigital numbers
multiplicand/multiplier/product only use 1-9

12 is smallest mutiplicand
123 is smallest multiplier

98 is largest multiplicand
987 is largest multiplier

98*765 = largest product
12*345 = smallest product
"""

def isPandigital(tpl):
    return tpl.__contains__("1") and tpl.__contains__("2") and \
           tpl.__contains__("3") and tpl.__contains__("4") and \
           tpl.__contains__("5") and tpl.__contains__("6") and \
           tpl.__contains__("7") and tpl.__contains__("8") and \
           tpl.__contains__("9")


def main():
    PRODUCTS = {}
    for a in range(1,10000):
        for b in range(1,10000):
            prod = a*b
            pString = str(prod)+str(a)+str(b)
            if not len(pString) == 9 or pString.__contains__('0'):
                continue
            if isPandigital(pString):
                #print pString
                PRODUCTS[prod] = pString
    print sum(PRODUCTS.keys())
    print PRODUCTS
if __name__ == "__main__":
    main()